package com.topscomm.meet.script;

import cn.hutool.core.date.DateUtil;
import com.tencentcloudapi.wemeet.common.exception.WemeetSdkException;
import com.tencentcloudapi.wemeet.models.meeting.QueryUserMeetingsResponse;
import com.topscomm.base.BaseRemindTemplate;
import com.topscomm.base.BaseSystemConst.NoticeTypeEnum;
import com.topscomm.base.BaseSystemConst.RemindTypeEnum;
import com.topscomm.base.BaseSystemConst.RemindUnitTypeEnum;
import com.topscomm.base.pojo.BasePermissionManageEntity;
import com.topscomm.base.pojo.BaseRemindConfigEntity;
import com.topscomm.base.pojo.BaseRemindTaskEntity;
import com.topscomm.base.service.impl.BaseCboUserExtendService;
import com.topscomm.base.service.impl.BasePermissionManageService;
import com.topscomm.basic.BasicEntity;
import com.topscomm.basic.util.Config;
import com.topscomm.cbo.pojo.CboApprovalNodeInsEntity;
import com.topscomm.cbo.pojo.CboDeptEntity;
import com.topscomm.cbo.pojo.CboRoleEntity;
import com.topscomm.cbo.service.impl.CboDeptService;
import com.topscomm.cbo.service.impl.CboRoleService;
import com.topscomm.meet.MeetScript;
import com.topscomm.meet.MeetSystemConst;
import com.topscomm.meet.MeetSystemConst.MeetPersonTypeEnum;
import com.topscomm.meet.pojo.MeetManageEntity;
import com.topscomm.meet.pojo.MeetRoomApplyEntity;
import com.topscomm.meet.service.impl.MeetRoomApplyService;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.SpringUtil;
import com.topscomm.tap.ITapService;
import com.topscomm.tap.TapEntity;
import com.topscomm.work.WorkSystemConst;
import com.topscomm.work.WorkSystemConst.WorkSourceTypeEnum;
import com.topscomm.work.pojo.WorkScheduleEntity;
import com.topscomm.work.service.impl.WorkScheduleService;
import org.springframework.beans.factory.annotation.Value;

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 会议室申请脚本
 * @description:
 * @author: chengengwei
 * @date: 2021-02-01
 * @modify:
 */
public class MeetRoomApplyScript extends MeetScript {
	@Value("${tencent.meet.production}")
	private boolean production;
	/**
	 * 会议室申请结束后操作
	 * @description:
	 * @author: chengengwei
	 * @date: 2021-02-01
	 * @modify:
	 */
	public void afterApplySuccessfullyFlow(ITapService service, TapEntity entity) {
		CboApprovalNodeInsEntity cboApprovalNodeInsEntity = (CboApprovalNodeInsEntity) entity;
		MeetRoomApplyService meetRoomApplyService = (MeetRoomApplyService) SpringUtil
				.getBean("meetRoomApplyService");
		MeetRoomApplyEntity meetRoomApplyEntity = meetRoomApplyService.queryById(ConvertUtil.
				convertToString(cboApprovalNodeInsEntity.getSourceid()));
		meetRoomApplyService.afterApplySuccessfullyFlow(meetRoomApplyEntity);
	}

	/**
	 * 发送消息给会议室申请第一个节点审批人
	 * @description:
	 * @author: chengengwei
	 * @date: 2021-08-05
	 * @modify:
	 */
	public void remindFirstNodeApprovalUser(ITapService service, TapEntity entity) {
		CboApprovalNodeInsEntity cboApprovalNodeInsEntity = (CboApprovalNodeInsEntity) entity;
		MeetRoomApplyService meetRoomApplyService = (MeetRoomApplyService) SpringUtil
				.getBean("meetRoomApplyService");
		MeetRoomApplyEntity meetRoomApplyEntity = meetRoomApplyService.queryById(ConvertUtil.
				convertToString(cboApprovalNodeInsEntity.getSourceid()));
		meetRoomApplyService.remindFirstNodeApprovalUser(meetRoomApplyEntity);
	}

	/***
	 * @description: 审批通过更新会议相关历史表
	 * @param service
	 * @param entity
	 * @return void
	 * @author: wangxinhua
	 * @date: 2023/3/30 13:59
	 * @modify:
	 */
	public void updateMeetHistoryInfo(ITapService service, TapEntity entity) throws WemeetSdkException {
		CboApprovalNodeInsEntity cboApprovalNodeInsEntity = (CboApprovalNodeInsEntity) entity;
		MeetRoomApplyService meetRoomApplyService = (MeetRoomApplyService) SpringUtil
				.getBean("meetRoomApplyService");
		MeetRoomApplyEntity meetRoomApplyEntity = meetRoomApplyService.queryById(ConvertUtil.
				convertToString(cboApprovalNodeInsEntity.getSourceid()));
		//进行线上会议室申请
		meetRoomApplyService.updateMeetHistoryInfo(meetRoomApplyEntity);
		meetRoomApplyService.deleteMeetRoomApply(meetRoomApplyEntity);

	}
	public void  CreatTencentMeet(ITapService service, TapEntity entity) throws WemeetSdkException, IOException {
		CboApprovalNodeInsEntity cboApprovalNodeInsEntity = (CboApprovalNodeInsEntity) entity;
		MeetRoomApplyService meetRoomApplyService = (MeetRoomApplyService) SpringUtil
				.getBean("meetRoomApplyService");
		MeetRoomApplyEntity meetRoomApplyEntity = meetRoomApplyService.queryById(ConvertUtil.
				convertToString(cboApprovalNodeInsEntity.getSourceid()));
		//进行线上会议室申请
		meetRoomApplyService.createTencentMeet(meetRoomApplyEntity);
	}
}
